#ifndef __SEU_KERNEL_H__
#define __SEU_KERNEL_H__
#include "seu_macro.h"
#include "seu_config.h"

typedef struct __SEU_TCB
{
    seu_stk *stk_ptr;
    seu_thread_state state;
    seu_uint32_t prio;
    seu_int32_t delay_time;
}SEU_TCB;

typedef struct __SEU_SYS
{
    seu_uint8_t os_running;
    seu_uint32_t sys_print_state;
    seu_uint32_t sys_clock_count;
    seu_uint32_t thread_slicetime;
    seu_uint32_t thread_slicetime_count;
    seu_uint8_t  lock_nesting;
    seu_uint8_t  int_nesting;
    seu_uint8_t  thread_cur_num; /*define highest prio thread in the rdy_tbl*/
#if (SEU_THREAD_MAX < 16)
    seu_uint8_t thread_rdy_tbl_bit[4];
#else
    seu_uint8_t thread_rdy_tbl_bit[8];
#endif
    seu_uint8_t thread_rdy_grp_bit;

}SEU_SYS;

#if (SEU_THREAD_MAX < 16)
extern seu_uint8_t const SEU_THREAD_MAP[16];
#else
extern seu_uint8_t const SEU_THREAD_MAP[256];
#endif

extern struct __SEU_TCB seu_tcb_list[SEU_THREAD_MAX];
extern struct __SEU_TCB *seu_tcb_cur;
extern struct __SEU_TCB *seu_tcb_rdy;
extern struct __SEU_SYS seu_sys;

// function define
void os_lock(void);
void os_unlock(void);
void os_switch(void);
void os_sched(void);
seu_rt seu_thread_create(void *func, seu_stk *ptopstk, seu_uint8_t prio);
seu_rt seu_thread_pend(seu_uint8_t prio);
seu_rt seu_thread_resume(seu_uint8_t prio);
seu_rt seu_thread_delete(seu_uint8_t prio);
void seu_thread_prio_set(seu_uint8_t prio, seu_uint8_t new_prio);
void seu_delay(seu_uint32_t tick);
void seu_sys_init(void);
void seu_sys_start(void);
void seu_systick_handler(void);

void _seu_user_init(void) __attribute__((weak));

#endif
